/* 
 * File:   Cache.h
 * Author: adminuser
 *
 * Created on April 16, 2012, 1:19 PM
 */

#ifndef CACHE_H
#define	CACHE_H
#include <map>
#include <queue>
#include <string>
#include <unistd.h>
#include <fcntl.h>
#include <cstdio>
#include <cstdlib>
#include <pthread.h>

#define MAXCACHE 102400
#define BUFSIZE 8192
using namespace std;
struct CacheItem
{
    long long filesize;
    char * data;
    pthread_mutex_t itemLock;
    CacheItem();
    CacheItem(long long length, int fd);
    ~CacheItem();
};
class Cache {
protected:
public:
    Cache();
    struct CacheItem FetchFromCache(string path);
private:
    map<string,struct CacheItem> cache;
    queue<string> files;
    long long maxCacheSize;
    long long currentCacheSize;
    void CacheInsert(string path, struct CacheItem item);
};

#endif	/* CACHE_H */

